package com.jerry.base.io.read;

import org.junit.Test;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

/**
 * Created with IntelliJ IDEA
 * User: Jerry
 * Date: 2024/1/27
 * Time: 18:30
 * Description:
 */
public class InputStreamReaderUsage {

    /**
     * 解决读取中文乱码问题
     *
     * @throws IOException
     */
    @Test
    public void read() throws IOException {
        String filePath = "src/main/resources/io/charset.txt";

        try(BufferedReader reader = new BufferedReader(new InputStreamReader(
                new FileInputStream(filePath), "GBK"))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        }
    }
}
